import topCommonTitleBar from '@/components/topCommonTitleBar/topCommonTitleBar.vue';
import { newGetMyAllTeam } from '@/api/my.js'
export default {
	comments: {
		topCommonTitleBar
	},
	data() {
		return {
			showRules: false,
			baseInfo: {},
			shareEwm: '',
			showMore: false,
			showBottom: false,
			path: '',
			list: {
				allcount: '',
				data: [],
				onecount: '',
				secondlist: '',
				content: ''
			},

			userList: [],
			page: 1,
			pageSize: 20,
			inviteType: [{
				index: 1,
				name: '直接邀请',
				type: 1
			}, {
				index: 2,
				name: '间接邀请',
				type: 2
			}],
			tabsIndex: 0,
			isLoading: true,

			status: 'nomore',
		};
	},
	onLoad(e) {
		this.baseInfo = uni.getStorageSync('userInfo') || {}
		this.shareEwm = this.baseInfo.share_ewm
		this.getInfo()
	},
	onNavigationBarButtonTap() {
		this.showRules = true
	},
	methods: {

		getInfo() {
			var that = this
			this.isLoading = true
			newGetMyAllTeam(({
				page: that.page,
				pageSize: that.pageSize,
				type: that.inviteType[that.tabsIndex].type
			})).then(res => {
				that.isLoading = false
				if (res.code == '1') {
					if (res.data.data.length >= that.pageSize) {
						that.status = 'more'
					} else {
						that.status = 'nomore'
					}
					that.list = res.data
					that.userList = res.data.data
				} else {
					that.$used.appBack(res.msg)
				}
			})
		},

		loadMore() {
			console.log('有没有走加载更多')
			if (this.status == 'more') {
				this.page++
				this.getInfo()
			}
		},

		changTabs(item, index) {
			this.tabsIndex = index
			this.userList = []
			this.page = 1
			this.getInfo()
		},
		openQrCode() {
			this.showMore = true
			this.showBottom = true
		},
		saveEwm() {
			let that = this;
			// #ifdef APP-PLUS
			const platform = uni.getSystemInfoSync().platform;
			if (platform === 'ios') {
				var result = permision.judgeIosPermission("photoLibrary")
				if (result == true) {
					that.downLoadImg()
				} else {
					that.isAuth()
				}
			}
			// #endif
		},
		downLoadImg() {
			uni.showLoading({
				title: '加载中'
			});
			let _that = this
			uni.downloadFile({
				url: _that.shareEwm,
				success: (res) => {
					if (res.statusCode === 200) {
						uni.saveImageToPhotosAlbum({
							filePath: res.tempFilePath,
							success: function () {
								uni.showToast({
									title: "保存到相册成功",
									icon: "none",
									success() {
										_that.showMore = false
									}
								});
							},
							fail: function (res) {
								console.log(res)
								uni.showToast({
									title: "因文件受限，请点击二维码预览并长按保存",
									icon: "none",
									duration: 2200,
								});
							}
						});
					}
				},
				fail: (err) => {
					uni.showToast({
						title: "失败啦",
						icon: "none"
					});
				}
			})
		},
		close() {
			this.showMore = false
			setTimeout(() => {
				this.showBottom = false
			}, 10)
		},
		openEwm() {
			uni.previewImage({
				urls: [this.shareEwm]
			})
		},
		/*
		 * 引导用户开启权限
		 */
		isAuth() {
			uni.showModal({
				content: '由于您还没有允许保存图片到您相册里,无法进行保存,请点击确定允许授权',
				success: (res) => {
					if (res.confirm) {
						permision.gotoAppPermissionSetting()
					}
				}
			});
		},
		//发送给朋友
		goShareWx() {
			uni.share({
				provider: "weixin",
				scene: "WXSceneSession",
				type: 2,
				imageUrl: this.shareEwm,
				success: function (res) {
					console.log("success:" + JSON.stringify(res));
					console.log(res)
					if (callback != null) {
						callback()
					}
					this.showMore = false
				},
				fail: function (err) {
					console.log("fail:" + JSON.stringify(err));
				}
			});
		},
	}
}